

use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m




capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff_c_reg


capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop df_reg


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff_c_reg=.


gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen df_reg=.

capture drop f_prix_ht f_prix_ht_temp 
capture drop f_prix_ht
gen f_prix_ht=0




foreach i of numlist 1/30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.local_shock10##(c.ratio c.mean c.sd c.skewness) c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l2.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l3.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l5.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness), absorb(id) vce(cluster daten)

	

	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr#c.skewness] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr#c.skewness] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}

preserve
keep coeff1_reg coeff2_reg coeff3_reg coeff4_reg coeff5_reg coeff_c_reg  se_coeff1_reg se_coeff2_reg se_coeff3_reg se_coeff4_reg se_coeff5_reg df_reg num_obs
gen name="BASELINE - interaction kurt freq - placebo"
gen charact="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER"
keep if num_obs<=40
save "$path\Graphs_Tables\Data_FigureC1.dta", replace
restore


clear 
use "$path\Graphs_Tables\Data_FigureC1.dta"



 
gen ci_coeff1_m=coeff1_reg-1.96*se_coeff1_reg
gen ci_coeff1_p=coeff1_reg+1.96*se_coeff1_reg
gen ci_coeff2_m=coeff2_reg-1.96*se_coeff2_reg
gen ci_coeff2_p=coeff2_reg+1.96*se_coeff2_reg
gen ci_coeff3_m=coeff3_reg-1.96*se_coeff3_reg
gen ci_coeff3_p=coeff3_reg+1.96*se_coeff3_reg
gen ci_coeff4_m=coeff4_reg-1.96*se_coeff4_reg
gen ci_coeff4_p=coeff4_reg+1.96*se_coeff4_reg
gen ci_coeff5_m=coeff5_reg-1.96*se_coeff5_reg
gen ci_coeff5_p=coeff5_reg+1.96*se_coeff5_reg

local nj=30
gen h=num_obs
sort h
graph twoway (rarea  ci_coeff1_m ci_coeff1_p h if h<=`nj', col(grey%10)) ///
(line  coeff1_reg h if h<=`nj', col(red) ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') ylabel(0(5)30) 

graph export "$path\Graphs_Tables\FigureC1_1.png", replace
graph export "$path\Graphs_Tables\FigureC1_1.eps", replace

local nj=30
sort h
graph twoway (rarea  ci_coeff2_m ci_coeff2_p h if h<=`nj', col(grey%10)) ///
(line  coeff2_reg h if h<=`nj', col(red)  ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') 

graph export "$path\Graphs_Tables\FigureC1_2.png", replace
graph export "$path\Graphs_Tables\FigureC1_2.eps", replace


local nj=30
sort h
graph twoway (rarea  ci_coeff3_m ci_coeff3_p h if h<=`nj', col(grey%10)) ///
(line  coeff3_reg h if h<=`nj', col(red)  ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') 

graph export "$path\Graphs_Tables\FigureC1_3.png", replace
graph export "$path\Graphs_Tables\FigureC1_3.eps", replace


local nj=30
sort h
graph twoway (rarea  ci_coeff4_m ci_coeff4_p h if h<=`nj', col(grey%10)) ///
(line  coeff4_reg h if h<=`nj', col(red)  ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') 

graph export "$path\Graphs_Tables\FigureC1_4.png", replace
graph export "$path\Graphs_Tables\FigureC1_4.eps", replace


local nj=30
sort h
graph twoway (rarea  ci_coeff5_m ci_coeff5_p h if h<=`nj', col(grey%10)) ///
(line  coeff5_reg h if h<=`nj', col(red)  ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') 

graph export "$path\Graphs_Tables\FigureC1_5.png", replace
graph export "$path\Graphs_Tables\FigureC1_5.eps", replace
